﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QUANLIBANHANG.ENTITY;
using QUANLIBANHANG.DAL;
using System.Data.SqlClient;

namespace QUANLIBANHANG.BUS
{
    public class SanphamBUS
    {
       
        
        public static void insertSP(SanphamEntity sp)
        {
            try
            {
                
                SanphamDAL.insertSP(sp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }
        public static void updateSP(SanphamEntity sp)
        {
            try
            {
                SanphamDAL.updateSP(sp);
            }
            catch(Exception ex)
            {
                throw ex;
            }
           
        }
        
        public static void deleteSP(SanphamEntity sp)
        {
            try
            {
                SanphamDAL.deleteSP(sp);

            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable getTableSP(string dk)
        {
            try
            {
                return SanphamDAL.getTableSP(dk);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataTable getSP()
        {
            try
            {
                return SanphamDAL.getSP();
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }
        // Hàm thực hiện tính toán khi mua hàng
        public static List<double> calculationThanhtien(double gia, double soluong, double ptgiamgia, double ptvat)
        {
            List<double> tien = new List<double>();
            double thanhtien = gia * soluong;
            tien.Add(thanhtien);
            double tiengiamgiam = thanhtien* (ptgiamgia / 100);//Tièn giam gia
            tien.Add(tiengiamgiam);
            double tienvat = (thanhtien - tiengiamgiam) * (ptvat / 100);// Tien Vat
            tien.Add(tienvat);
            double tienthanhtoan = thanhtien - tiengiamgiam + tienvat;// Tien thanh toán
            tien.Add(tienthanhtoan);
            return tien;
        }

        public static int deleteSP1(SanphamEntity sp)
        {
           return SanphamDAL.deleteSP1(sp);
        }
        public static DataTable getTableWhere(SanphamEntity sp)
        {
            try
            {
                return SanphamDAL.getSPWhere(sp);
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }
       
    }
}
